package com.lianniu.mgr.teaComment.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.constants.ErrorCode;
import com.lianniu.mgr.pagination.PaginationInfo;
import com.lianniu.mgr.teaComment.dao.TeaCommentDao;
import com.lianniu.mgr.teaComment.model.TeaComment;
import com.lianniu.mgr.teaComment.service.ITeaUserCommentService;
import com.lianniu.mgr.util.StringUtil;

@Service
@Transactional
public class TeaUserCommentServiceImpl implements ITeaUserCommentService {
	
	private final static Logger logger = Logger.getLogger(TeaUserCommentServiceImpl.class);

	
	@Autowired
	private TeaCommentDao teaCommentDao;
	
//	@Autowired
//	private TeaEvaDao teaEvaDao;
	
	public BaseResult saveComment(TeaComment teaComment) {
		logger.info("TeaUserCommentServiceImpl saveComment start");
		teaCommentDao.insert(teaComment);
		logger.info("TeaUserCommentServiceImpl saveComment end");
		return BaseResult.success(teaComment);
	}

	
	public BaseResult getCommentListALl(String orderId,String userId) {
		logger.info("TeaUserCommentServiceImpl getCommentListALl start");
		Map<String,String> param = new HashMap<String,String>();
		param.put("orderId", orderId);
		param.put("userId", userId);
		List<TeaComment> teaComments = teaCommentDao.selectAllByOederId(param);
//		for (TeaComment teaComment : teaComments) {
//			String commentId = teaComment.getId();
//			List<TeaEva> teaEvas = teaEvaDao.selectTeaEvaByCommentId(commentId);
//			teaComment.setTeaEvas(teaEvas);
//		}
		logger.info("TeaUserCommentServiceImpl getCommentListALl end");
		return BaseResult.success(teaComments);
	}

	
	public BaseResult getCommentListPart(String orderId) {
		logger.info("TeaUserCommentServiceImpl getCommentListPart start");
		List<TeaComment> teaComments = teaCommentDao.selectPartByOederId(orderId);
		logger.info("TeaUserCommentServiceImpl getCommentListPart end");
		return BaseResult.success(teaComments);
	}


	@Override
	public BaseResult getCommentListPage(TeaComment teaComment, PaginationInfo paginationInfo) {
		teaComment.setPaginationInfo(paginationInfo);
		List<TeaComment> teaCommentList = teaCommentDao.getTeaCommentListForPage(teaComment);
		Map<String, Object> retmap = new HashMap<String, Object>();
	    retmap.put("total", paginationInfo.getTotalRecord());
	    retmap.put("curPage", paginationInfo.getCurPage());
	    retmap.put("rows", teaCommentList);
		return BaseResult.success(retmap);
	}


	@Override
	public BaseResult deleteComment(String... id) {
		logger.info("deleteComment begin");
	    logger.info("deleteComment Ids:" +id.toString());
	    logger.info("deleteComment: input data check begin");
	   
	    BaseResult baseResult;
	    if (StringUtil.isEmpty(id.toString())) {
	      baseResult =  BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
	      return baseResult;
	    }
	    logger.info("deleteProductAssess: input data check end");
	    
	    return BaseResult.success(teaCommentDao.deleteComment(id));
	}

}
